<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
    <script>var jsCtx = "${ctx}"</script>
<!-- 引入easyui样式 -->
<link rel="stylesheet" type="text/css" href="<%=basePath%>/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>/easyui/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>/easyui/demo/demo.css" />
<script type="text/javascript" src="<%=basePath%>/backstage/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/easyui/jquery.easyui.min.js"></script>
<!-- 引入kineditor -->
<link href="<%=basePath%>/backstage/css/user.css" rel="stylesheet" />
<link href="<%=basePath%>/backstage/css/default.css" rel="stylesheet" />
<script type="text/javascript" src="<%=basePath%>/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="<%=basePath%>/kindeditor/lang/zh_CN.js"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta charset="UTF-8">
	<title>DataGrid with Toolbar - jQuery EasyUI Demo</title>
</head>
<script type="text/javascript">
$(document).ready(function(){
 $("#edit_user").window('close');
if(${statelist==1}){
$("#edit_user").window('open');
}

});
</script>
<script type="text/javascript">
function update(){
var url=jsCtx +'/scholararticle/addscholararticle';
var params = {
            id:$("#id").val(),
			articletitle:$("#articletitle").val(),
			sholar:$("#sholar").val(),
			content:editor.html()
	};
$.post(url,params,function(data){
    var obj = eval( "(" + data + ")" );
	if(obj.state == 0){
		alert("提交成功");
		//刷新页面
		$("#edit_user").window('close');
		//window.location.reload();
		}else{
		alert("提交失败");
		}
	});
}

</script>
  <script type="text/javascript">  
  function deletes(){        
            var url=jsCtx +'/scholararticle/deletescholararticle';
            var params = {
            id:$("#id").val()
            };
           $.post(url,params,function(data){
                   var obj = eval( "(" + data + ")" );
	                if(obj.state == 0){
		            alert("删除成功");
					//刷新页面
					window.location.reload();
				}else{
		            alert("删除失败");
		             }
	            });
	    }        
	</script>

<body>

<table id="dg"></table>
	<div id="edit_user" class="easyui-window" title="编辑文章" style="width:1200px; height:500px;">
	    <div style="margin: 10px 0;"></div>
	    <div style="padding: 10px 0 10px 60px">
        <form id="add" method="post">
            <table>
                <tr>
                    <td>文章标题:</td>
                    <td>
                    <input class="easyui-validatebox" type="hidden" id="id"></input>
                        <input class="easyui-validatebox" type="text" id="articletitle"></input></td>
                </tr>
                
                <tr>
                <td>发布学者:</td>
                    <td>
                    <select id="sholar" name="sholar">
                           <!--  <option value="000">请选择</option> -->
                            	<c:forEach var="scholar" items="${scholarList}">
                               <option value="${scholar.name}">
                                 ${scholar.name}
                                  </option>
                               </c:forEach>
                   </select>
                  </tr>
                
                <tr>
                    <td>文章内容:</td>
                    <td>
                    <!--  onclick="alert(editor.html())" -->
                        <textarea name="txtContent" id="txtContent" style="width: 220%; height: 350px; visibility: hidden;"></textarea>
                        <input type="button" name="btn1" value="提交" onclick="update()" />
                    </td>
                </tr>
       
            </table>
        </form>
    </div>
   </div>
   	<script type="text/javascript">
        //kindeditor编辑器
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="txtContent"]', {
                allowFileManager: true,
                resizeType: 1,
                allowPreviewEmoticons: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                    'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
                afterChange: function () {
                    this.sync();
                }
            });
        });
    </script>
<script type="text/javascript">
    $(function(){
    //alert("<%=request.getContextPath()%>");
        $('#dg').datagrid({   
         width: 1200, 
         height: 'auto', 
           url:'<%=request.getContextPath()%>/scholararticle/article_list', 
            singleSelect:true,//是否单选 
            columns:[[    
                {field:'id',title:'文章编号',width:0,align:'center' },    
                {field:'articletitle',title:'文章标题',width:240,align:'left'},  
                 {field:'scholarname',title:'文章作者',width:40,align:'center'},
                {field:'createtime',title:'创建时间',width:80,align:'center'},
                {field:'readingcount',title:'点击量',width:200,align:'center'},
                {field:'articlecontent',title:'文章内容',width:200,align:'left',resizable:true}  
            ]],
      toolbar: [{ 
            text: '添加', 
            iconCls: 'icon-add', 
            handler: function() { 
           //openDialog("add_dialog","add"); 
            location.href=jsCtx +'/scholararticle/scholar_list';
             //$("#edit_user").window('open');
             /*   $('#edit_user').window({
    			 modal:true   
          }); */ 
            } 
        }, '-', { 
            text: '修改', 
            iconCls: 'icon-edit', 
            handler: function() { 
                //openDialog("add_dialog","edit"); 
                  // var a=${news.title};
                //    location.href=jsCtx +'/scholararticle/scholar_list';
               var rows= $('#dg').datagrid('getSelections'); 
               data=rows[0].title;
               //把增加新闻修改为修改新闻
               $("#id").val(rows[0].id);
               $("#articletitle").val(rows[0].articletitle);
               //去除两边的空格
                $("#sholar").val(rows[0].sholar);
              // $("#position").val(rows[0].position.replace(/^\s+|\s+$/g,""));
               //对kindeditor取值采用editor.html
               editor.html(rows[0].articlecontent);
               //editor.html(rows[0].content.replace(/^\s+|\s+$/g,""));
               $('#edit_user').window({
          }); 
            } 
        }, '-',{ 
            text: '删除', 
            iconCls: 'icon-remove', 
            handler: function(){ 
             var rows= $('#dg').datagrid('getSelections'); 
             $("#id").val(rows[0].id);
                deletes(); 
            } 
        }], 
            fitColumns:true,
            striped:true,
            pagination:true,
            rownumbers:true,
            pageNumber:1,
        }); 
     $('#dg').datagrid('hideColumn','articlecontent');
     $('#dg').datagrid('hideColumn','id');
    //设置分页控件 
    var p = $('#dg').datagrid('getPager'); 
    $(p).pagination({ 
        pageSize: 10,//每页显示的记录条数，默认为10 
        pageList: [5,10,15,20],//可以设置每页记录条数的列表 
        beforePageText: '第',//页数文本框前显示的汉字 
        afterPageText: '页    共 {pages} 页', 
        displayMsg: '当前显示 第{from} - {to} 条记录   共 {total} 条记录', 
        /*onBeforeRefresh:function(){
            $(this).pagination('loading');
            alert('before refresh');
            $(this).pagination('loaded');
        }*/ 
    }); 
       })
</script>
   
</body>
</html>
